package com.cat.dynamicPlanning;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-absolute-sum-of-any-subarray/
 * @create 2025/8/29 20:40
 * @since JDK17
 */

public class Solution23 {
    public int maxAbsoluteSum(int[] nums) {
        int n = nums.length, ans = Math.max(0, nums[0]);
        int[] dp1 = new int[n], dp2 = new int[n];
        dp1[0] = dp2[0] = nums[0];
        for (int i = 0; i < n; i++) {
            dp1[i] = dp2[i] = nums[0];
            dp1[i] += Math.max(0, dp1[i - 1]);
            dp2[i] += Math.min(0, dp2[i - 1]);
            ans = Math.max(ans, Math.max(dp1[i], -dp2[i]));
        }
        return ans;
    }
}
